﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DLL.Entities;
using DLL;
using System.Xml.Serialization;
using System.IO;
using System.Xml;


namespace RAD
{
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        Target newTarget = new Target();

        private void btnRandom_Click(object sender, EventArgs e)
        {
            int target;   

            Random random = new Random((int)DateTime.Now.Ticks);
            /**************************
             * target 1 = bird
             * target 2 = missile
             * target 3 = fighter jet
             * target 4 = commercial airliner
             * ************************/
            target = random.Next(1, 5);
            newTarget.TargetLocation = random.Next(0, 360);
            switch (target)
            {
                case 1:
                    {
                        newTarget.TargetSpeed = random.Next(1, 60);
                        newTarget.TargetAltitude = random.Next(1, 8000);
                        newTarget.TargetDistance = random.Next(5, 30);
                        newTarget.TargetSize = "Small";
                    }
                    break;
                case 2:
                    {
                        newTarget.TargetSpeed = random.Next(1000, 6000);
                        newTarget.TargetAltitude = random.Next(30, 125000);
                        newTarget.TargetDistance = random.Next(10, 50);
                        newTarget.TargetSize = "Small";
                    }
                    break;
                case 3:
                    {
                        newTarget.TargetSpeed = random.Next(1000, 2200);
                        newTarget.TargetAltitude = random.Next(30, 120000);
                        newTarget.TargetDistance = random.Next(10, 50);
                        newTarget.TargetSize = "Medium";
                    }
                    break;
                case 4:
                    {
                        newTarget.TargetSpeed = random.Next(165, 750);
                        newTarget.TargetAltitude = random.Next(0, 50000);
                        newTarget.TargetDistance = random.Next(10, 2000);
                        newTarget.TargetSize = "Large";
                    }
                    break;
            }
            textAltitude.Text = Convert.ToString(newTarget.TargetAltitude);
            textDirection.Text = Convert.ToString(newTarget.TargetLocation);
            textSpeed.Text = Convert.ToString(newTarget.TargetSpeed);
            textSize.Text = Convert.ToString(newTarget.TargetSize);
            textLocation.Text = Convert.ToString(newTarget.TargetDistance);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Target));
            string FileToWrite = "../../../RAD/RadarXML.xml";
            XMLHandler.WRITEXML(newTarget, FileToWrite, serializer);

            textAltitude.Clear();
            textDirection.Clear();
            textLocation.Clear();
            textSize.Clear();
            textSpeed.Clear();
        }

        private void Status_Writer_Tick(object sender, EventArgs e)
        {
            Status status = new Status();

            status.console = "RAD";
            status.status = Convert.ToString(DateTime.Now);

            XmlSerializer serializer = new XmlSerializer(typeof(Status));
            string fileToSave = "../../../RAD/RADStatus.xml";

            XMLHandler.WRITEXML(status, fileToSave, serializer);
        }
    }
}
